package com.ybkj.o2o.zhuanche.mapper;

import com.ybkj.o2o.zhuanche.common.CompanyOrderVo;
import com.ybkj.o2o.zhuanche.common.DriverOrderDetailVo;
import com.ybkj.o2o.zhuanche.common.DriverOrderVo;
import com.ybkj.o2o.zhuanche.common.MemberOrderVo;
import com.ybkj.o2o.zhuanche.common.query.OrderQuery;
import com.ybkj.o2o.zhuanche.entity.Order;
import com.ybkj.o2o.zhuanche.entity.OrderCriteria;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.session.RowBounds;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import java.util.Map;

public interface OrderMapper extends BaseMapper<Order, OrderCriteria, Long> {
  Long countByExample(OrderCriteria example);

  int deleteByExample(OrderCriteria example);

  int deleteByPrimaryKey(Long id);

  int insert(Order record);

  int insertSelective(Order record);

  List<Order> selectByExampleWithRowbounds(OrderCriteria example, RowBounds rowBounds);

  List<Order> selectByExample(OrderCriteria example);

  Order selectByPrimaryKey(Long id);

  int updateByExampleSelective(@Param("record") Order record,
      @Param("example") OrderCriteria example);

  int updateByExample(@Param("record") Order record, @Param("example") OrderCriteria example);

  int updateByPrimaryKeySelective(Order record);

  int updateByPrimaryKey(Order record);

  long finishOrderCount(@Param("startDate") Date startDate, @Param("endDate") Date endDate,
      @Param("companyId") Long companyId, @Param("appKey") String appKey);

  long destroyOrderCount(@Param("startDate") Date startDate, @Param("endDate") Date endDate,
      @Param("companyId") Long companyId, @Param("appKey") String appKey);

  Order selectFinishedByDriverWithDate(@Param("employId") Long employId,
      @Param("start") Date start, @Param("end") Date end, @Param("offset") Integer offset,
      @Param("size") Integer size, @Param("appKey") String appKey);

  List<Order> selectMonthOrder(@Param("start") Date start, @Param("end") Date end,
      @Param("appKey") String appKey);

  long countFinishedByMemberWithFinishTime(@Param("passengerId") Long passengerId);

  BigDecimal sumMoneyByMemberWithFinishTime(@Param("passengerId") Long passengerId);

  List<MemberOrderVo> selectMemberOrder(@Param("startTime") Date startTime,
      @Param("endTime") Date endTime, @Param("companyId") Long companyId,
      @Param("appKey") String appKey);

  List<String> queryAllFromSource(
      @Param("companyId") Long companyId, @Param("appKey") String appKey);

  Map<String, Object> findByFromSource(@Param("start") Date start, @Param("end") Date end,
      @Param("companyId") Long companyId, @Param("fromSource") String fromSource,
      @Param("appKey") String appKey);

  List<Map<String, Object>> findDetailByFromSource(@Param("start") Date start,
      @Param("end") Date end, @Param("companyId") Long companyId,
      @Param("fromSource") String fromSource, @Param("appKey") String appKey);

  List<DriverOrderVo> queryAllDriverAchievement(@Param("start") Date start, @Param("end") Date end,
      @Param("empCompanyId") Long empCompanyId, @Param("appKey") String appKey);

  List<String> queryAllCompany(@Param("appKey") String appKey);

  List<CompanyOrderVo> companyOrders(@Param("start") Date start, @Param("end") Date end,
      @Param("appKey") String appKey);

  List<CompanyOrderVo> companyCancelNums(@Param("start") Date start, @Param("end") Date end,
      @Param("appKey") String appKey);

  List<DriverOrderDetailVo> queryDetailByDriverId(@Param("driverId") Long driverId,
      @Param("start") Date start, @Param("end") Date end, @Param("offset") Integer offset,
      @Param("rows") Integer rows, @Param("appKey") String appKey);

  List<Order> selectByParams(OrderQuery orderQuery);
  
  List<Order> selectByParamsInBook(OrderQuery orderQuery);
  
  Long countByParamsInBook(OrderQuery orderQuery);

  Long countByParams(OrderQuery orderQuery);

  Order selectByIdAndAppKey(@Param("orderId") Long orderId, @Param("appKey") String appKey);

  Long countRunningOrder(@Param("carTypeId") Long carTypeId, @Param("appKey") String appKey);

  List<Order> findHastenOrder(@Param("appKey") String appKey);

  List<Order> exportOrders(OrderQuery orderQuery);

  /**
   * 订单的基本信息.
   */
  Order selectOneOrder(@Param("orderId") Long orderId, @Param("appKey") String appKey);

  /**
   * 查询指定服务人员完成订单的部分属性.
   */
  List<Order> selectFinishOrder(OrderQuery orderQuery);
  
  List<Order> selectFinishOrderByEmploy(OrderQuery orderQuery);
  
  Long countFinishOrderByEmploy(OrderQuery orderQuery);

  /**
   * 统计指定服务人员完成订单数量.
   */
  Long countFinishOrder(OrderQuery orderQuery);

  /**
   * 后台查询订单列表专用接口.
   */
  List<Order> selectOrders(OrderQuery orderQuery);

  /**
   * 查询司机已接单,执行中,未确认的订单.
   */

  List<Order> selectByEmployId(OrderQuery orderQuery);

  /**
   * 查询单个订单结算.
   */
  Order selectPrepare(@Param("orderId") Long orderId, @Param("appKey") String appKey);

  /**
   * 修改订单完成时间.
   */
  int updateFinishTime(@Param("orderId") Long orderId, @Param("appKey") String appKey);

  /**
   * 司机提成.
   * total:单量,total_pay:总支付金额,total_coupon:总优惠券金额,total_company_profit:公司提成,total_employ_profit
   */
  Map<String, Object> countFinishByCompay(@Param("companyId") Long companyId,
      @Param("startTime") Date startTime, @Param("endTime") Date endTime,
      @Param("appKey") String appKey);

  Long countRunByCompany(@Param("companyId") Long companyId, @Param("startTime") Date startTime,
      @Param("endTime") Date endTime, @Param("appKey") String appKey);

  /**
   * 司机提成.
   * total:单量,total_pay:总支付金额,total_coupon:总优惠券金额,total_company_profit:公司提成,total_employ_profit
   */
  Map<String, Object> countFinishByNotCompay(@Param("companyId") Long companyId,
      @Param("startTime") Date startTime, @Param("endTime") Date endTime,
      @Param("appKey") String appKey);


  Long countRunByNotCompany(@Param("companyId") Long companyId, @Param("startTime") Date startTime,
      @Param("endTime") Date endTime, @Param("appKey") String appKey);

  Long countCancelByCompany(@Param("companyId") Long companyId, @Param("startTime") Date startTime,
      @Param("endTime") Date endTime, @Param("appKey") String appKey);

  Map<String, Object> countFinishByNotCompanyAndDriver(@Param("companyId") Long companyId,
      @Param("startTime") Date startTime, @Param("endTime") Date endTime,
      @Param("appKey") String appKey);

  Long countRunByNotCompanyNotDriver(@Param("companyId") Long companyId,
      @Param("startTime") Date startTime, @Param("endTime") Date endTime,
      @Param("appKey") String appKey);

  long countCancelAll(@Param("startTime") Date startTime, @Param("endTime") Date endTime,
      @Param("appKey") String appKey);

  /**
   * 统计主公司订单数量.
   * total:单量,real_pay:总金额,coupon_money:优惠券金额,zhifu_pay:支付金额,company_profit:公司提成,emp_profit:服务人员提成
   *         ,guolu_money:过路费
   */
  Map<String, Object> countMain(@Param("startTime") Date startTime, @Param("endTime") Date endTime,
      @Param("appKey") String appKey);

  List<Map<String, Object>> chartFinishDate(@Param("start") Date start, @Param("end") Date end,@Param("appKey")String appKey);

  List<Map<String, Object>> chartCancel(@Param("start") Date start, @Param("end") Date end,@Param("appKey")String appKey);

  long countByAppKey(@Param("startTime") Date startTime, @Param("endTime") Date endTime,
      @Param("appKey") String appKey);

  Long driverOrderDetailCount(OrderQuery orderQuery);

  List<Map<String,Object>> countOrderNumByDriver(@Param("driverIds") Long[] driverIds, @Param("start") Date start, @Param("end") Date end, @Param("appKey") String appKey);

  Map<String,Object> countOnDutyByDriver(@Param("driverId") Long driverId, @Param("start") Date start, @Param("end") Date end);
  
  List<Map<String,Object>> countBookDriver(@Param("zhuanYuyueMax") Long zhuanYuyueMax, @Param("zhuanYuyueTime") Date zhuanYuyueTime,
	      @Param("appkey") String appKey);
  
  List<Map<String,Object>> findDriverBusy(@Param("zhuanYuyueMax") Long zhuanYuyueMax, @Param("zhuanYuyueTime") Date zhuanYuyueTime,
		  @Param("appkey") String appKey,@Param("employId")Long employId);
  
  List<Map<String,Object>> countBusyBookDriver(@Param("zhuanYuyueTime") Date zhuanYuyueTime, @Param("appkey") String appKey);
  
  Integer getTodayBooks(@Param("employId") Long employId,@Param("start") Date start,@Param("end") Date end);
}
